package com.znsd.zl.app.housecollect.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.znsd.zl.app.housecollect.dao.IHouseCollectDao;
import com.znsd.zl.app.housecollect.entity.HouseCollectEntity;
import com.znsd.zl.app.housecollect.service.IHouseCollectService;
import com.znsd.zl.app.housecollect.vo.HouseCollectPageReqVO;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @ClassName HouseCollectServiceImpl
 * @Description 用户收藏房屋业务层接口实现类
 * @Author jaypdd
 * @Date 2020/8/22 20:49
 * @Version v1.0
 */
@Service
public class HouseCollectServiceImpl extends ServiceImpl<IHouseCollectDao, HouseCollectEntity>
		implements IHouseCollectService {

	/**
	 * 用户收藏房屋信息
	 * @param entity    收藏的房屋以及用户信息
	 * @return  收藏成功 true 失败 false
	 */
	@Override
	public boolean save(HouseCollectEntity entity) {
		entity.setCreateTime(new Date());
		return super.save(entity);
	}


	/**
	 * 根据用户id分页查询该用户收藏的所有房屋信息
	 * @param reqVO 请求的分页参数以及用户id VO对象
	 * @return      返回收藏的房屋列表
	 */
	@Override
	public IPage<HouseCollectEntity> queryPage(HouseCollectPageReqVO reqVO) {
		IPage<HouseCollectEntity> page = new Page(reqVO.getPageNum(), reqVO.getPageSize());
		List<HouseCollectEntity> list = this.baseMapper.pageSelectHouseCollect(page, reqVO);
		page.setRecords(list);
		return page;
	}
}
